//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2011 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_ALGORITHM_JOIN_H_
#define _BUOLA_ALGORITHM_JOIN_H_

#include <buola/algorithm/container.h>
#include <buola/iterator/range.h>

namespace buola {

///\addtogroup algorithm
///@{

///\name Join
//@{

///joins the strings in \p pSrc into a single string

///Strings are concatenated by the given separator \p pSep.
///
///\return The concatenated string
template<typename tSrc,typename tSep>
ORangeValue<tSrc> join(const tSrc &pSrc,const tSep &pSep)
{
    auto lI=range_begin(pSrc);
    auto lE=range_end(pSrc);
    
    typename tSrc::value_type lResult;
    
    //Append first element
    if(lI!=lE)
    {
        lResult.insert(lResult.end(),range_begin(*lI),range_end(*lI));
    
        while(++lI!=lE)
        {
            lResult.insert(lResult.end(),range_begin(pSep),range_end(pSep));
            lResult.insert(lResult.end(),range_begin(*lI),range_end(*lI));
        }
    }
    
    return lResult;
}

//@}

///@}

/*namespace buola*/ }

#endif
